package com.alex.projects.bitcask.api;

import lombok.Getter;

import java.nio.charset.StandardCharsets;
import java.util.Objects;

/**
 * 用于存储的Key结构
 */
@Getter
public class StoreKey {

    private String keyStr;

    private byte[] bytes;

    private short keyLen;

    public StoreKey(String keyStr) {
        this.keyStr = keyStr;
        this.bytes = keyStr.getBytes(StandardCharsets.UTF_8);
        this.keyLen = (short) bytes.length;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        StoreKey storeKey = (StoreKey) o;
        return Objects.equals(keyStr, storeKey.keyStr);
    }

    @Override
    public int hashCode() {
        return Objects.hash(keyStr);
    }
}
